package team.yidong.fenda.wx.Service.Impl;

import net.sf.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import team.yidong.fenda.entity.Answer;
import team.yidong.fenda.repository.AnswerRepository;
import team.yidong.fenda.wx.Service.WxListenService;

/**
 * Created by xuanlong on 2017/12/8.
 */
@Service
public class WxListenServiceImpl implements WxListenService {
    @Autowired
    AnswerRepository answerRepository;

    @Transactional
    @Override
    public String listen(String answerId) {
        JSONArray jsonArray = JSONArray.fromObject(answerId);
        for (int i = 0; i < jsonArray.size(); i++) {
            Answer answer = answerRepository.findOne((Integer) jsonArray.get(i));
            answer.setListenTime(answer.getListenTime() + 1);
            answerRepository.save(answer);
        }
        return null;
    }
}
